package com.le.tester.book.concurrentchallenge.atomicnoblocking15;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * createTime：2025-05-25 11:07
 * description：
 */
public class AtomicPseudoRandom {
    private AtomicInteger seed;

    public AtomicPseudoRandom(int seed) {
        this.seed = new AtomicInteger(seed);
    }

    public int nextInt(int n) {
        while (true) {
            int s = seed.get();
            int nextSeed = calculateNext(s);
            if (seed.compareAndSet(s, nextSeed)) {
                int remain = s % n;
                return remain > 0 ? remain : remain + n;
            }
        }
    }

    private int calculateNext(int s) {
        return 0;
    }


}
